﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;

namespace DS.Controls
{
    public partial class DSFolderListItem : DSkin.DirectUI.DuiBaseControl
    {
        public Common.TaskItemData TaskitemData;
        public DSFolderListItem()
        {
            InitializeComponent();
        }

        public DSFolderListItem(Common.TaskItemData itemData)
        {
            InitializeComponent();
            this.TaskitemData = itemData;
            StateShow(itemData);
        }

        public DSFolderListItem(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        public string Path
        {
            get => ItemData.importpath;
        }

        public void SetState(TaskItemState itemState)
        {
            TaskitemData.taskItemState = itemState;
            StateShow(TaskitemData);
        }

        private void StateShow(Common.TaskItemData itemData)
        {
            Invoke(new System.Windows.Forms.MethodInvoker(()=> {
                this.duiLabel1.Text = this.ItemData.importpath;
                this.duiLabel2.Text = this.ItemData.taskItemState.ToString();
                if (itemData.taskItemState == TaskItemState.complete)
                {
                    this.duiButton1.Visible = true;
                }
                else
                {
                    this.duiButton1.Visible = false;
                }
            }));

        }

        public TaskItemState State
        {
            get => ItemData.taskItemState;
        }
        public TaskItemData ItemData { get => TaskitemData; }

        private void DSListBoxItem_IsSelectedChanged(object sender, EventArgs e)
        {
            if (this.IsSelected)
            {
                //this.BackgroundImage = Properties.Resources.list_item_select;
                this.BackgroundRender.BackgroundBrush = SelectedColor;
            }
            else
            {
                //this.BackgroundImage = null;
                this.BackgroundRender.BackgroundBrush = BaseColor;
            }
        }

        private void DSListBoxItem_MouseEnter(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (this.IsSelected)
            {
                this.BackgroundRender.BackgroundBrush = SelectedHoverColor;
            }
            else
            {
                this.BackgroundRender.BackgroundBrush = HoverColor;
            }
        }

        private void DSListBoxItem_MouseLeave(object sender, EventArgs e)
        {
            if (this.IsSelected)
            {
                this.BackgroundRender.BackgroundBrush = SelectedColor;
            }
            else
            {
                this.BackgroundRender.BackgroundBrush = BaseColor;
            }
        }

        private void duiButton1_MouseClick(object sender, DSkin.DirectUI.DuiMouseEventArgs e)
        {
            Console.WriteLine(ItemData.exportpath);
            //SHOpenFolder.ExplorerFile(itemData.exportpath);
            SHOpenFolder.ExplorerFile(@"\\CE_CLOUD_3\project_1\FeiQ2013\FeiQ.exe");
        }
    }
}
